Skip to content

LVT-382: Batch worker imports to allow database idle windows - #132

Merged
jackshim415 merged 2 commits into
mainfrom
jackshim415/lvt-382-worker-batch-imports-to-maximize
Nov 19, 2026
Merged

jackshim415 merged 2 commits into
mainfrom
jackshim415/lvt-382-worker-batch-imports-to-maximize

Conversation

@jackshim415

@jackshim415 jackshim415 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What changed

Background imports currently poll PostgreSQL all day. Add a finite WORKER_MODE=batch that snapshots due work, processes each job at most once with bounded consumers and fresh atomic leases, drains heartbeats, disconnects Prisma and exits. Retries and newly discovered child jobs wait for the next external window. Continuous mode remains the default for minute-level competition refreshes.

Move remaining API team/match timers and cleanup ownership to the durable Worker queue. Daily maintenance preserves read-time expiry and thirty-day draft payload retention; successful archived imports and explicit gap jobs finalize instead of recurring forever. Add opt-in Railway Cron rendering and a preview/production/rollback runbook. Related: LVT-335 and LVT-376; broader resource tuning stays with those issues.

Areas affected

  • Server
  • Shared documentation, CI, or deployment
  • Worker

Contracts and data

  • No API, report-schema, authentication, deep-link, season-metric, or database contract changed
  • Tenant and source-team visibility was reviewed
  • No credentials, production data, or private scouting notes are included

Verification

  • Worker: typecheck and 66 PostgreSQL/fixture tests passed; added maintenance retention integration test also passed (67 total).
  • Server under Node 22.20.0: build, typecheck, test typecheck, all 1,454 behavioral tests passed; lint passed with 79 existing warnings. Edited Server files pass Prettier.
  • Railway IaC: typecheck and all 5 configuration tests passed.
  • Structure and git diff --check passed.

Deployment

No migrations. Deploy Worker first and verify maintenance before API cutover; old API replicas retain timers until drained. Existing deployments remain continuous unless the Cron graph is explicitly applied. Daily 18:00 UTC is provisional; pre-event windows run four times/day. Schedule both event-mode cutovers before enabling Cron. Bootstrap catalog child jobs with a second batch.

Actual Railway sleep/billing and cold-start measurements remain pending operational gates. The plugin account exposes only crux, but the local CLI has Lovat access and Railway automatically provisions this PR's preview. No Cron or PostgreSQL sleep settings were applied. Keep LVT-382 open for the evidence and rollout gates in docs/worker-batch-rollout.md; this PR does not claim measured savings.

Snapshot due jobs once, preserve leases and retries, and disconnect after draining. Move API maintenance into the worker and finalize archived imports so scheduled offseason windows can finish. Keep continuous event mode as the default until Railway preview sleep and cold-start gates are verified.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T16:12:06.017238Z ce3668a PR opened
🔒 Security Review ✅ Completed 2026-11-19T16:16:03.187279Z ce3668a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@railway-app

railway-app Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

🚅 Deployed to the lovat-pr-132 environment in lovat

Service Status Web Updated
dashboard ✅ Success (View Logs) Web Nov 19, 2026 at 4:12 pm UTC
worker ❌ Build Failed (View Logs) Nov 19, 2026 at 4:12 pm UTC
api ✅ Success (View Logs) Web Nov 19, 2026 at 4:12 pm UTC
website ✅ Success (View Logs) Web Nov 19, 2026 at 4:11 pm UTC
learn ✅ Success (View Logs) Web Nov 19, 2026 at 4:11 pm UTC
1 service not affected by this PR
  • support

@github-actions

Copy link
Copy Markdown
Contributor

📱 Connect your app to this PR deployment

Scan a QR code to use this PR's Server API. Worker changes use the same API;
the Worker has no public app endpoint.

Server URL: https://api-lovat-pr-132.up.railway.app

Lovat Collection

QR code — Lovat Collection

lovat-collection://set-url?u=https%3A%2F%2Fapi-lovat-pr-132.up.railway.app

Lovat Dashboard

QR code — Lovat Dashboard

com.frc8033.lovatdashboard:///set-url?u=https%3A%2F%2Fapi-lovat-pr-132.up.railway.app

@github-actions

Copy link
Copy Markdown
Contributor

Lovat AI review failed

Status: failed · Model: z-ai/glm-5.3-flash

The automated review did not complete. The latest commit has not been fully reviewed. This is not a clean review.

Error: OpenRouter stopped because the output token limit was reached. Increase maxOutputTokens or reduce the review batch size.

Unreviewed commit: fa365e6c428d91514f403297ab932a641aa14b69

View the workflow run

Push a new commit or re-run the workflow after fixing the failure.

@jackshim415 jackshim415 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the batch snapshot/claim boundary, fresh lease timing, token-fenced completion/finalization, retry preservation, heartbeat draining, API import ownership, maintenance retention and both deployment graphs. No blocking code findings in this revision. Local verification: 67 Worker tests (66 suite plus the added maintenance integration), 1,454 Server tests, Server build/typechecks/lint and five IaC tests. The separate Codex code review completed without findings on the identical implementation commit; the latest commit only corrects operational documentation. The OpenRouter review hit its output limit and is being retried. Actual database sleep/billing, cold-query latency and scheduled operating-mode cutovers remain rollout gates, not verified savings.

@jackshim415 jackshim415 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final merge review: required Monorepo CI passed, including Server, Worker and cross-app contracts; Railway IaC and CodeQL analysis also passed. The optional OpenRouter reviewer failed twice on its 16,384-token output limit, so it did not provide a completed review. This is an infrastructure limitation, not a passing review. Manual review and the separate Codex code review found no blocking code issues. No merge-rule bypass is needed: the repository requires Monorepo CI, which is green. Rollout sleep/cost/cold-start evidence remains pending as documented.

@jackshim415
jackshim415 merged commit 2b2fcfa into main Nov 19, 2026
24 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant